home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex8-6.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  36 lines

  1. // ex8-6.c -- Sequential access to Objects in an OrderedCltn
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex8-6.c,v 3.0 90/05/15 22:46:22 kgorlen Rel $
  4.  
  5. #include "OrderedCltn.h"
  6. #include "Iterator.h"
  7. #include "Patient.h"
  8.  
  9. main()
  10. {
  11. // new Patient objects to put in OrderedCltn
  12.     Patient* p1 =new Patient("Smith John A.","111-22-3333",22222);
  13.     Patient* p2 =new Patient("Fried Harry I.","123-45-6789",22221);
  14.     Patient* p3 =
  15.       new Patient("Chavez Maria G.","444-555-6666",22223);
  16.  
  17. // add each Patient to OrderedCltn
  18.     OrderedCltn patientlist(1);// capacity=1 (default=16)
  19.     patientlist.add(*p1);      // at[0] in order
  20.     patientlist.add(*p2);      // at[1] in order
  21.     patientlist.add(*p3);      // at[2] in order
  22.  
  23.     cout << "ACCESS OBJECTS WITH operator[]():" << endl;
  24.     for(int i=0; i<patientlist.size(); i++) {
  25.         Patient& p = *(Patient*)patientlist[i];
  26.         cout << p << endl;
  27.     }
  28.  
  29.     cout << "ACCESS OBJECTS WITH Iterator:" << endl;
  30.     Iterator it(patientlist);
  31.     while ( it++ ) {
  32.         Patient& p = *(Patient*)it();
  33.         cout << p << endl;
  34.     }
  35. }
  36.